package com.neurotech.pcc.ui


import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.NavOptions
import androidx.navigation.Navigation
import com.neurotech.pcc.R
import com.neurotech.pcc.other.Utils

/**
 * A Splash Fragment class.
 * @author shenhua
 */
class SplashFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_splash, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        view.postDelayed({
            if (activity != null && !activity?.isFinishing!!) {
                val options = NavOptions.Builder().setClearTask(true)
                if (Utils.isLogin(activity!!)) {
                    Navigation.findNavController(view).navigate(R.id.action_splashFragment_to_mainFragment, null, options.build())
                } else {
                    Navigation.findNavController(view).navigate(R.id.action_splashFragment_to_loginFragment, null, options.build())
                }
            }
        }, 2000)
    }
}
